<?php

namespace app\adminapi\controller;

use think\Controller;

class BaseApi extends Controller
{
    /*通用响应
  
    */
    public function response($code=200,$msg='',$data=[]){
        //返回结果
        $res=[
            'code'=>$code,
            'msg'=>$msg,
            'data'=>$data,
        ];
        // 返回组装好的
        json($res)->send();die;
    }
    //成功时的响应
    public function ok($data=[],$msg='success',$code=200){
        $this->response($code,$msg,$data);
    }
    //失败时的响应
    public function fail($msg='fail',$code=500){
        $this->response($code,$msg);
    }
}